<?php

use Illuminate\Database\Seeder;

class AdminTablesSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // base tables
        Encore\Admin\Auth\Database\Menu::truncate();
        Encore\Admin\Auth\Database\Menu::insert([
                [
                    'parent_id' => 0,
                    'order' => 1,
                    'title' => 'Dashboard',
                    'icon' => 'fa-bar-chart',
                    'uri' => '/',
                ],
                [
                    'parent_id' => 0,
                    'order' => 2,
                    'title' => 'Admin',
                    'icon' => 'fa-tasks',
                    'uri' => '',
                ],
                [
                    'parent_id' => 2,
                    'order' => 3,
                    'title' => 'Users',
                    'icon' => 'fa-users',
                    'uri' => 'auth/users',
                ],
                [
                    'parent_id' => 2,
                    'order' => 4,
                    'title' => 'Roles',
                    'icon' => 'fa-user',
                    'uri' => 'auth/roles',
                ],
                [
                    'parent_id' => 2,
                    'order' => 5,
                    'title' => 'Permission',
                    'icon' => 'fa-ban',
                    'uri' => 'auth/permissions',
                ],
                [
                    'parent_id' => 2,
                    'order' => 6,
                    'title' => 'Menu',
                    'icon' => 'fa-bars',
                    'uri' => 'auth/menu',
                ],
                [
                    'parent_id' => 2,
                    'order' => 7,
                    'title' => 'Operation log',
                    'icon' => 'fa-history',
                    'uri' => 'auth/logs',
                ],
            ]
        );

        Encore\Admin\Auth\Database\Permission::truncate();
        Encore\Admin\Auth\Database\Permission::insert(
            [
                [
                    'name' => 'All permission',
                    'slug' => '*',
                    'http_method' => '',
                    'http_path' => '*',
                ],
                [
                    'name' => 'Dashboard',
                    'slug' => 'dashboard',
                    'http_method' => 'GET',
                    'http_path' => '/',
                ],
                [
                    'name' => 'Login',
                    'slug' => 'auth.login',
                    'http_method' => '',
                    'http_path' => "/auth/login\r\n/auth/logout",
                ],
                [
                    'name' => 'User setting',
                    'slug' => 'auth.setting',
                    'http_method' => 'GET,PUT',
                    'http_path' => '/auth/setting',
                ],
                [
                    'name' => 'Auth management',
                    'slug' => 'auth.management',
                    'http_method' => '',
                    'http_path' => "/auth/roles\r\n/auth/permissions\r\n/auth/menu\r\n/auth/logs",
                ],
            ]
        );

        Encore\Admin\Auth\Database\Role::truncate();
        Encore\Admin\Auth\Database\Role::insert(
            [
                'name' => 'Administrator',
                'slug' => 'administrator',
            ]
        );

        // pivot tables
        DB::table('admin_role_menu')->truncate();
        DB::table('admin_role_menu')->insert(
            [

            ]
        );

        DB::table('admin_role_permissions')->truncate();
        DB::table('admin_role_permissions')->insert(
            [

            ]
        );
        Encore\Admin\Auth\Database\Administrator::truncate();
        Encore\Admin\Auth\Database\Administrator::create([
            'username' => 'admin',
            'password' => bcrypt('admin'),
            'name'     => 'Administrator',
        ]);
        Encore\Admin\Auth\Database\Role::first()->permissions()->save(Encore\Admin\Auth\Database\Permission::first());
        Encore\Admin\Auth\Database\Administrator::first()->roles()->save(Encore\Admin\Auth\Database\Role::first());
        // finish
    }
}
